'''
Created on 27/04/2012

@author: Bruna, Bruno
'''

from statistic_helper import calculate_histogram
from color_helper import calculate_rgb_normalized
import csv

class DataExtractor:
    '''
        Reads a file that contains measures of red, green and blue (by cap) of a color and draws an average per cap value   
    '''
    def __init__(self, file_name, histogram_interval_count = 45, histogram_upper_bound = 1.0):
        self.file_name = 'resources\\' + file_name
        self.reader = self.__create_CSVReader()
        self.histogram_interval_count = histogram_interval_count
        self.histogram_upper_bound = histogram_upper_bound
        self.histogram = None

    def __create_CSVReader(self):
        file_handler = open(self.file_name)
        return csv.DictReader(file_handler)
    
    def extract_data(self):
        data = []
    
        for row in self.reader:
            normalized_r, normalized_g, normalized_b = calculate_rgb_normalized(int(row['Red']), int(row['Green']), int(row['Blue']))
            data.append((normalized_r, normalized_g, normalized_b))
            
        self.histogram = calculate_histogram(data, self.histogram_interval_count, self.histogram_upper_bound)